<template>
    <div>
        <p style="padding:10px;">在终端的bash环境中执行如下命令，会自动安装和注册客户端（根据实际网络情况修改 <span style="color:red;">server_ip</span> 和 <span style="color:red;">server_port</span> ）</p>
        <div style="padding:10px;background-color:#f5f5f5;border-radius:5px;word-wrap: break-word;word-break: break-all;overflow: auto;"><pre><code>{{ client_install_cmd }}</code></pre></div>
        <Button @click="handleCopyClientInstallCmd" style="margin-top: 10px;">点击复制</Button>
    </div>
</template>

<script>
import { mapGetters } from 'vuex';

export default {
    name: "InstallClientView",
    data() {
        return {
        }
    },
    computed: {
        ...mapGetters([ 'configs' ]),
        client_install_cmd() {
            const server_ip = this.configs.cmd_server_ip || this.$http.server_ip;
            const server_port = this.configs.cmd_server_port || this.$http.server_port;
            return `server_ip=${server_ip}&&server_port=${server_port}&&mkdir -p client_monitor&&wget http://$server_ip:$server_port/client_monitor.sh -O client_monitor/client_monitor.sh&& chmod +x client_monitor/client_monitor.sh&&./client_monitor/client_monitor.sh install $server_ip $server_port&&./client_monitor/client_monitor.sh register`;
        }
    },
    methods: {
        handleCopyClientInstallCmd() {
            this.$copyText(this.client_install_cmd).then(() => {
                this.$Message.success('复制成功');
            }, () => {
                this.errorMessage('复制失败');
            });
        },
    },
}
</script>